package functions;

import main.ContingencyTable;

public class YulesYFunction extends GeneralFunction {

	public YulesYFunction(String name) {
		super(name);
	}

	@Override
	public double calculate(ContingencyTable t) {
		return (Math.sqrt(pXY(t) * p_X_Y(t)) - Math.sqrt(pX_Y(t) * p_XY(t)))
		/ (Math.sqrt(pXY(t) * p_X_Y(t)) + Math.sqrt(pX_Y(t) * p_XY(t)));
	}
	
	private double pXY(ContingencyTable t) {
		return t.f11() / t.N();
	}

	private double p_X_Y(ContingencyTable t) {
		return t.f00() / t.N();
	}

	private double pX_Y(ContingencyTable t) {
		return t.f10() / t.N();
	}

	private double p_XY(ContingencyTable t) {
		return t.f01() / t.N();
	}

}
